package com.woniu.platform.contorller;

import com.woniu.platform.service.PlatformMenuService;
import com.woniu.platform.service.PlatformRoleMenuService;
import com.woniu.util.utils.HttpResult;
import com.woniu.util.utils.MenuTree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("menu")
public class PlatformMenuController {
    @Autowired
    private PlatformRoleMenuService platformRoleMenuService;

    @Autowired
    private PlatformMenuService platformMenuService;

    /**
     * 通过用户的账号获取菜单
     * @param account
     * @return
     */
    @GetMapping("getmenu")
    public HttpResult<?> queryPlatformMenuListByAccount(String account){
        return platformMenuService.queryPlatformMenuByAccount(account);
    }

    /**
     * 查询所有的菜单
     */
    @GetMapping("menulist")
    public HttpResult queryPlatformMenuList(){
        return platformMenuService.queryallMenu();
    }

    /**
     * 查询不同身份所拥有的菜单id
     * @param rid
     * @return
     */
    @GetMapping("rolelist")
    public HttpResult queryRolelist(Integer rid){
        return platformRoleMenuService.queryRoleMenuMap(rid);
    }

    /**
     * 修改角色对应菜单
     * @param menuTree
     * @return
     */
    @PostMapping("update")
    public HttpResult updateuandMenu(@RequestBody MenuTree menuTree){
        return platformRoleMenuService.savaMenu(menuTree);
    }
}
